<?php require '../../sesionabierta.php'; ?>
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>Conexi&oacute;n</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="">

    <!-- Le styles -->
    <link href="../../../css/bootstrap.css" rel="stylesheet">
    <link href='../../../css/estiloprincipal.css ' rel='stylesheet'>
    <link href="../../../css/bootstrap-responsive.css" rel="stylesheet">
    <link rel="shortcut icon" href="../../../img/user1_monitor.ico"/>

  <body>

    <?php require '../../menu_logueo.php';?>
    <div class="container-fluid">
      <div class="row-fluid">
        <?php include '../listadoServicios.php'; ?>
        <div class="span9">
          <div class="hero-unit">
            <h3>Modificar Credenciales</h3>
            <script>
            function compara(){
                if(document.fom1.password.value !== document.form1.password_nueva.value){
                    alert('Las contraseñas no son identicas');
                    return false;
                }else{
                    return true;
                }
            }
            
            </script>
            
            <form id="form1" method="POST" action="modificarCredenciales.php" >
            <table border="0">
                <tbody>
                    <?php 

                    $consulta = "SELECT * FROM usuarios_cliente where id=". $_SESSION['id']."";
                    $resultado = mysql_query($consulta, $enlace);

                        while ($row = mysql_fetch_array($resultado)) {
                            $id = $row['id'];
                            $_SESSION['usuario'] = $row['usuario'];
                            $password = $row['password'];
                        }               
                    ?>
                    <tr><input type="hidden" name="id" value="<?php echo $id?>"/>
                        <td>Usuario:</td>
                        <td><input type="text" name="usuario" required="" value="<?php echo $_SESSION['usuario']?>"/></td>
                    </tr>
                    <tr>
                        <td>Password Nueva:</td>
                        <td><input type="password" name="pwd1"  required pattern="(?=.*\d)(?=.*[a-z])(?=.*[A-Z])\w{6,}" onchange="form.pwd2.pattern = this.value;" value=""/></td>
                    </tr>
                    <tr>
                        <td>Confirmar password:</td>
                        <td><input type="password" name="pwd2" required pattern="(?=.*\d)(?=.*[a-z])(?=.*[A-Z])\w{6,}" title="Debe coincidir con el campo anterior" value=""/></td>
                    </tr>
                    <tr>
                        <td><input type="submit" name="guardar" value="Guardar" class="btn btn-success" ></td>
                    </tr>
                </tbody>
            </table>
            </form>
            <?php
                    if (isset($_POST['guardar'])) {
                    $guardar = $_POST['guardar'];

                    if ($guardar == "Guardar"){
                        
                        $id = $_POST['id'];
                        $usuario = $_POST['usuario'];
                        $password = md5($_POST['pwd1']);


                    $modificar = "UPDATE usuarios_cliente SET usuario='$usuario', password='$password'"
                                       . "WHERE id = $id";

                    $query = mysql_query($modificar, $enlace);
                    if (!$query) {
                        echo 'No se modifico'.mysql_error();
                    }  else {   
                         echo "<script>alert('Credencial modificada');window.location.href=\"../../../logout.php\"</script>";
                    }       
                }
              }            
            ?>
          </div>
        </div><!--/span-->
      </div><!--/row-->

      <hr>
      <footer>
        <center><p>&copy; Conexi&oacute;n 2013</p></center>
      </footer>

    </div><!--/.fluid-container-->

    <!-- Le javascript
    ================================================== -->
    <!-- Placed at the end of the document so the pages load faster -->
    <script src="../../../js/jquery.js"></script>
    <script src="../../../js/bootstrap-alert.js"></script>
    <script src="../../../js/bootstrap-dropdown.js"></script>

  </body>
</html>
